![]() ![]() |
The Sitecore security database provides a working example of the security database. The definition of this database in web.config is (expanded for clarity):
<database id="security" singleInstance="true"
type="Sitecore.Data.Database, Sitecore.Kernel">
<param desc="name">$(id)</param>
<dataProviders
hint="list:AddDataProvider">
<dataProvider
type="Sitecore.Data.DataProviders.TemplateFileResolver,
Sitecore.Kernel">
<param desc="template
file">/sitecore/shell/Security templates.xml</param>
<abortChain>true</abortChain>
</dataProvider>
<dataProvider
ref="dataProviders/sqlserver" param1="$(id)"/>
</dataProviders>
</database>
As can be seen, the database employs two data providers, a TemplateFileResolver and a SqlServerDataProvider.
The special thing about the security database is that in all respects it is a standard SQL Server based database, except for the fact that it does not include any templates. Thus, the SqlServerDataProvider has no way of supplying templates to the DataManager. And without templates, items won't work.
By chaining data providers it is possible to insert a data provider that fills in the missing part of the puzzle: Getting templates. That is what the TemplateFileResolver does. It is a data provider which only overrides a single method, namely GetTemplates(). Specifically, it responds to a GetTemplates() call by reading an xml file with template definitions and uses those to build a list of Template objects that are returned to the DataManager. For performance reasons, it then aborts further processing of the chain.
The end result is that the DataManager gets the templates it needs to work with items from the TemplateFileResolver and everything else it gets from the SqlServerDataProvider.
The example shows that data providers need not be all-encompassing and implement all methods, but they may do very specific (and powerful) things by only implementing one or a two methods.
![](/SdnArchive/images/sdn5/prev.gif)
![](/SdnArchive/images/sdn5/next.gif)